﻿using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x0200057A RID: 1402
	public class VoiceList : MonoBehaviour
	{
		// Token: 0x17000451 RID: 1105
		// (get) Token: 0x060023C8 RID: 9160 RVA: 0x000D73F4 File Offset: 0x000D55F4
		// (set) Token: 0x060023C9 RID: 9161 RVA: 0x000D7404 File Offset: 0x000D5604
		public bool active
		{
			get
			{
				return base.gameObject.activeSelf;
			}
			set
			{
				if (base.gameObject.activeSelf != value)
				{
					base.gameObject.SetActive(value);
				}
				if (!base.gameObject.activeSelf)
				{
					this.group = -1;
					this.category = -1;
				}
			}
		}

		// Token: 0x060023CA RID: 9162 RVA: 0x000D7444 File Offset: 0x000D5644
		public void InitList(int _group, int _category)
		{
			if (!Utility.SetStruct<int>(ref this.group, _group) && !Utility.SetStruct<int>(ref this.category, _category))
			{
				return;
			}
			int childCount = this.transformRoot.childCount;
			for (int i = 0; i < childCount; i++)
			{
				UnityEngine.Object.Destroy(this.transformRoot.GetChild(i).gameObject);
			}
			this.transformRoot.DetachChildren();
			this.scrollRect.verticalNormalizedPosition = 1f;
			foreach (KeyValuePair<int, Info.LoadCommonInfo> keyValuePair in Singleton<Info>.Instance.dicVoiceLoadInfo[_group][_category])
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.objectPrefab);
				if (!gameObject.activeSelf)
				{
					gameObject.SetActive(true);
				}
				gameObject.transform.SetParent(this.transformRoot, false);
				VoiceNode component = gameObject.GetComponent<VoiceNode>();
				int no = keyValuePair.Key;
				component.addOnClick = delegate()
				{
					this.OnSelect(no);
				};
				component.text = keyValuePair.Value.name;
			}
			this.active = true;
			this.group = _group;
			this.category = _category;
		}

		// Token: 0x060023CB RID: 9163 RVA: 0x000D75B4 File Offset: 0x000D57B4
		private void OnSelect(int _no)
		{
			OCIChar[] array = (from v in Singleton<GuideObjectManager>.Instance.selectObjectKey
			select Studio.GetCtrlInfo(v) as OCIChar into v
			where v != null
			select v).ToArray<OCIChar>();
			int num = array.Length;
			for (int i = 0; i < num; i++)
			{
				array[i].AddVoice(this.group, this.category, _no);
			}
			this.voiceControl.InitList();
		}

		// Token: 0x040024B6 RID: 9398
		[SerializeField]
		private Transform transformRoot;

		// Token: 0x040024B7 RID: 9399
		[SerializeField]
		private GameObject objectPrefab;

		// Token: 0x040024B8 RID: 9400
		[SerializeField]
		private ScrollRect scrollRect;

		// Token: 0x040024B9 RID: 9401
		[SerializeField]
		private VoiceControl voiceControl;

		// Token: 0x040024BA RID: 9402
		private int group = -1;

		// Token: 0x040024BB RID: 9403
		private int category = -1;
	}
}
